package com.ruoyi.terminal.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.terminal.domain.DcTermattr;
import com.ruoyi.terminal.service.IDcTermattrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 属性管理Controller
 * 
 * @author ruoyi
 * @date 2020-12-23
 */
@RestController
@RequestMapping("/attr")
public class DcTermattrController extends BaseController
{
    @Autowired
    private IDcTermattrService dcTermattrService;

    /**
     * 查询属性管理列表
     */
    @PreAuthorize(hasPermi = "terminal:attr:list")
    @GetMapping("/list")
    public TableDataInfo list(DcTermattr dcTermattr)
    {
        startPage();
        List<DcTermattr> list = dcTermattrService.selectDcTermattrList(dcTermattr);
        return getDataTable(list);
    }

    /**
     * 导出属性管理列表
     */
    @PreAuthorize(hasPermi = "terminal:attr:export")
    @Log(title = "属性管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DcTermattr dcTermattr) throws IOException
    {
        List<DcTermattr> list = dcTermattrService.selectDcTermattrList(dcTermattr);
        ExcelUtil<DcTermattr> util = new ExcelUtil<DcTermattr>(DcTermattr.class);
        util.exportExcel(response, list, "attr");
    }

    /**
     * 获取属性管理详细信息
     */
    @PreAuthorize(hasPermi = "terminal:attr:query")
    @GetMapping(value = "/{termImei}")
    public AjaxResult getInfo(@PathVariable("termImei") String termImei)
    {
        return AjaxResult.success(dcTermattrService.selectDcTermattrById(termImei));
    }

    /**
     * 新增属性管理
     */
    @PreAuthorize(hasPermi = "terminal:attr:add")
    @Log(title = "属性管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DcTermattr dcTermattr)
    {
        return toAjax(dcTermattrService.insertDcTermattr(dcTermattr));
    }

    /**
     * 修改属性管理
     */
    @PreAuthorize(hasPermi = "terminal:attr:edit")
    @Log(title = "属性管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DcTermattr dcTermattr)
    {
        return toAjax(dcTermattrService.updateDcTermattr(dcTermattr));
    }

    /**
     * 删除属性管理
     */
    @PreAuthorize(hasPermi = "terminal:attr:remove")
    @Log(title = "属性管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{termImeis}")
    public AjaxResult remove(@PathVariable String[] termImeis)
    {
        return toAjax(dcTermattrService.deleteDcTermattrByIds(termImeis));
    }
}
